
package de.swta.freezay.components;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.basic.MultiLineLabel;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.panel.Panel;

/**
 * A OptionContentPanel displays a message and two links/options (yes and no)
 *
 * @author Jan Korreck
 */
public abstract class OptionContentPanel extends Panel {

    /**
     * Constructor
     *
     * @param id the markupID
     */
    public OptionContentPanel(String id) {
        super(id);

        /* create the form component */
        Form form = new Form("form");

        /* set up a feedback panel to display mesages */
        final FeedbackPanel feedback = new FeedbackPanel("feedback");
        feedback.setOutputMarkupId(true);
        form.add(feedback);
        /* add form component to this panel */
        add(form);

        /* add text label */
        add(new Label("textLabel", ""));

        /* add "on confirm" behaviour (call abstract method onSelect) */
        form.add(new AjaxLink("confirmLink"){
            // <editor-fold defaultstate="collapsed" desc="confirm behaviour">
            public void onClick(AjaxRequestTarget target) {
                onSelect(target, new String("confirm was clicked"));
                target.addComponent(feedback);
            }
            // </editor-fold>
        });

        /* add "cancel" behaviour (call abstract method onCancel) */
        form.add(new AjaxLink("cancelLink"){
            // <editor-fold defaultstate="collapsed" desc="cancel behaviour">
            public void onClick(AjaxRequestTarget target) {
                onCancel(target);
            }
            // </editor-fold>
        });
    }


    /**
     * Sets the message text of this component
     *
     * @param text the message text to set
     */
    public void setMessageText(String text) {
        this.remove("textLabel");
        add(new MultiLineLabel("textLabel", text));
    }


    /**
     * Called if cancel is clicked
     *
     * @param target the ajax request target
     */
    public abstract void onCancel(AjaxRequestTarget target);

    /**
     * Called if select is clicked
     *
     * @param target the ajax request target
     * @param selection the selection string
     */
    public abstract void onSelect(AjaxRequestTarget target, String selection);

}

